﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace GestorDeFlotasDesktop.UILogic.Helpers
{
    /// <summary>
    /// Métodos helpers de seguridad
    /// </summary>
    class SecurityHelpers
    {
        /// <summary>
        /// Método estático para hashear la contraseña con SHA256
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string PasswordHashed(string value)
        {
            var encoder = new UTF8Encoding();
            var sha256hasher = new SHA256Managed();
            byte[] hashedDataBytes = sha256hasher.ComputeHash(encoder.GetBytes(value));
            return byteArrayToString(hashedDataBytes);
        }

        private static string byteArrayToString(byte[] inputArray)
        {
            var output = new StringBuilder("");
            for (int i = 0; i < inputArray.Length; i++)
            {
                output.Append(inputArray[i].ToString("X2"));
            }
            return output.ToString();
        }
    }
}
